﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class mystudy_video_load : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getPlayList();
        }
    }
    /// <summary>
    /// 获取播放器播放列表
    /// </summary>
    private void getPlayList()
    {
        string msg = string.Empty;
        string playlist = string.Empty;
        string title = string.Empty;
        bool status = true;
        string id = Request["id"];
        if (!Regex.IsMatch(id, "^[0-9]*$"))
        {
            messageBox(false, "", "参数不合法！");
        }
        if (status)
        {
            using (Conn sqlCon = new Conn())
            {
                string sql = string.Format("select f_content,f_title from bbs where title_id={0}", id);
                DataView dr = sqlCon.GetGrid(sql, "list");
                DataTable dt0 = dr.ToTable();
                if (dt0.Rows.Count > 0)
                {
                    status = true;
                    msg = dt0.Rows[0]["f_content"].ToString();
                    title = Server.HtmlEncode(dt0.Rows[0]["f_title"].ToString());
                    sql = string.Format("select img_id,title_id,f_truename,dirName,f_filename,innerOrder,convertstatus from imgupload where title_id={0} and (convertStatus!=6 or convertStatus is null) order by innerOrder", id);
                    DataView dr1 = sqlCon.GetGrid(sql, "playlist");
                    DataTable dt = dr1.ToTable();
                    if (dr1.Count == 0)
                    {
                        status = false;
                        msg = "该课程没有上传视频";
                    }
                    else
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            string path = row["dirName"].ToString().Replace("\\", "/") + row["f_filename"].ToString();
                            playlist += string.IsNullOrEmpty(playlist) ? "{url:\"" + path + "\"}" : ",{url:\"" + path + "\"}";
                        }
                    }
                }
                else
                {
                    status = false;
                    msg = "你所观看的课程不存在";
                }
            }

        }
        Response.Write("{\"status\":" + status.ToString().ToLower() + ",\"msg\":\"" + msg + "\",\"list\":[" + playlist + "],\"title\":\"" + title + "\"}");
        Response.End();
    }
    /// <summary>
    /// 提示消息
    /// </summary>
    /// <param name="tag"></param>
    /// <param name="message">正确时提示消息</param>
    /// <param name="message1">错误时提示消息</param>
    void messageBox(bool tag, string message, string message1)
    {
        if (tag)
        {
            Response.Write(string.Format("<script language='javascript'>alert('{0}');</script>", message));
        }
        else
        {
            Response.Write(string.Format("<script language='javascript'>alert('{0}');</script>", message1));
        }
    }
}
